package cn.tedu._10security.base.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig {
	@Bean
	public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
		http.
		authorizeHttpRequests(authorize -> authorize
				.requestMatchers("/api/public/**").permitAll() //不认证
				.anyRequest().authenticated() //认证
		)
				.formLogin(form -> form
						.permitAll()
				)
				.logout(logout -> logout
						.permitAll()
				);
				return http.build();
	}
}